package com.coszero.utils.utils

import java.util.Random

/**
 * Desc： 获取随机数信息
 *
 *
 * Author： xmqian
 * Email:xmqian93@163.com
 * Date: 2019/7/5 16:07
 * @version 1
 */
object RandomUtils {
    @JvmStatic
    val randownColor: Int
        /**
         * @return 返回随机颜色 以 0xff8800格式
         */
        get() {
            val random: Random = Random()
            val ranColor: Int = -0x1000000 or random.nextInt(0x00ffffff)
            return ranColor
        }

    /**
     * 获取指定位数的随机字符串(包含小写字母、大写字母、数字,0<length></length>)
     *
     * @param length
     * @return
     */
    fun getRandomString(length: Int): String {
        //随机字符串的随机字符库
        val KeyString: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        val sb: StringBuffer = StringBuffer()
        val len: Int = KeyString.length
        for (i in 0 until length) {
            sb.append(KeyString.get(Math.round(Math.random() * (len - 1)).toInt()))
        }
        return sb.toString()
    }
}
